import os
import time
from socket import socket, AF_INET, SOCK_STREAM
def a(name):
    s= socket(AF_INET,SOCK_STREAM)
    s.connect(('localhost',20000))
    time.sleep(0.1)
    s.send(b'hello')
    s.recv(8192)
    print('Run child process %s (%s)...' % (name, os.getpid()))

if __name__ == '__main__':
    from multiprocessing import Process
    # for i in range(100):
    #     p = Process(target=a,args=(i,))
    #     p.start()
    #
    # print('子进程end')
    import threading
    for i in range(1000):
        p = threading.Thread(target=a,args=(i,))
        p.daemon = False
        p.start()

    print('thread %s ended.' % threading.current_thread().name)